package com.wise.site.more;

import com.wise.site.R;
import com.wise.site.WiseSiteApplication;
import com.wise.site.protocol.result.AboutUSResult;
import com.wise.site.utils.ImageLoader;
import com.wise.site.utils.ImageLoader.Imager;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class AboutUSActivity extends Activity implements View.OnClickListener {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.more_about_us_activity);
		((TextView)findViewById(R.id.activity_title)).setText(getString(R.string.aboutUS));
		findViewById(R.id.title_back).setOnClickListener(this);
		findViewById(R.id.company_name).setOnClickListener(this);
		findViewById(R.id.company_phone).setOnClickListener(this);
		findViewById(R.id.company_email).setOnClickListener(this);
		findViewById(R.id.company_website).setOnClickListener(this);
		
		bindData(WiseSiteApplication.getContext().getModelResult().aboutUS);
	}
	
	private void bindData(AboutUSResult result){
//		ImageLoader.getInstance().DisplayImage(new Imager(result.logoUrl, (ImageView)findViewById(R.id.logo)));
		((TextView)findViewById(R.id.company_name_text)).setText(result.companyName);
		((TextView)findViewById(R.id.company_phone_text)).setText(result.phoneNumber);
		((TextView)findViewById(R.id.company_email_text)).setText(result.email);
		((TextView)findViewById(R.id.company_website_text)).setText(result.website);
		((TextView)findViewById(R.id.company_introduction)).setText(Html.fromHtml(result.introduction));
	}
	
	@Override
	public void onClick(View view) {
		Intent intent = new Intent();
		int id = view.getId();
		switch(id){
		case R.id.title_back:
			finish();
			break;
		case R.id.company_name:
			
			break;
		case R.id.company_phone:
			intent.setAction(Intent.ACTION_DIAL);
			intent.setData(Uri.parse("tel:" + ((TextView)findViewById(R.id.company_phone_text)).getText().toString()));
			startActivity(intent);
			break;
		case R.id.company_email:
			
			intent.setAction(Intent.ACTION_SEND);
			//intent.setType("text/plain");//模拟器
			intent.setType("message/rfc822");//真机
			intent.putExtra(Intent.EXTRA_EMAIL, new String[]{((TextView)findViewById(R.id.company_email_text)).getText().toString()});//发到
			//intent.putExtra(Intent.EXTRA_SUBJECT,"subject goes here");//主题
			//intent.putExtra(Intent.EXTRA_TEXT,"body goes here");//内容
			startActivity(Intent.createChooser(intent, "请选择邮件发送程序"));
			
			
			/*intent.setAction(Intent.ACTION_SENDTO);
			intent.setType("text/plain");
			intent.putExtra(android.content.Intent.EXTRA_EMAIL, ((TextView)findViewById(R.id.company_email_text)).getText().toString());
			startActivity(Intent.createChooser(intent, getString(R.string.choose_email_app)));*/
			break;
		case R.id.company_website:
			intent.setAction(Intent.ACTION_VIEW);
			intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); 
			intent.setData(Uri.parse(((TextView)findViewById(R.id.company_website_text)).getText().toString()));
			startActivity(intent);
			break;
		}
	}

}
